#include <iostream>
#include <fstream>
#include <iterator>
#include <vector>
#include <map>
#include <list>
#include <deque>
#include <queue>
#include <stack>
#include <set>

using namespace std;

template<class container>
void showContainer(const container& c,const char* sep=" ",std::ostream& where=std::cout){
	typename container::const_iterator iter=c.begin();
	while(iter!=c.end()){
		where<<*iter++<<sep;
	}
	where<<endl;
}

int main(){
	vector<int> v;
	list<int> l;
	deque<int> d;

	for(int i=0;i<10;i++){
		v.push_back(rand());
		l.push_back(rand());
		d.push_back(rand());
	}
	
	l.sort();
	
	list<int> l2(5);
	l2.push_back(3);
	l.merge(l2);
	
	cout<<"vector:\n";
	copy(v.begin(),v.end(),ostream_iterator<int>(cout," "));
	cout<<"list:\n";
	copy(l.begin(),l.end(),ostream_iterator<int>(cout," "));
	cout<<"deque:\n";		
	copy(d.begin(),d.end(),ostream_iterator<int>(cout," "));
	
	vector<string> vs;
	int a='a'+0;
	for(int i=0;i<10;i++){
		const char c[]={rand()%26+a,'\0'};
		vs.push_back(string(c));
	}
	
	cout<<"strings:\n";
	copy(vs.begin(),vs.end(),ostream_iterator<string>(cout," "));
	cout<<"\n";
	showContainer(vs);
	cout<<"\n";
	
	ifstream source("ch1.cpp");
	istream_iterator<string> ipos(source),end;
	list<string> str;
	if(ipos==end){
		cout<<"file not found\n";
	}else{
		while(ipos!=end)
			str.push_back(*ipos++);
	}
	copy(str.begin(),str.end(),ostream_iterator<string>(cout," "));
	cout<<"\n";
	
	queue<int,list<int> > q;
	q.push(rand());
	
	priority_queue<int,vector<int>,greater<int> > ap;
	for(int i=0;i<10;i++){
		ap.push(rand()%100);
	}
	//copy(ap.begin(),ap.end(),ostream_iterator<int>(cout," "));
	while(!ap.empty()){
		int z=ap.top();
		cout<<z<<" ";
		ap.pop();
	}
	
	map<string,string> phone_book;
	phone_book["liqiang"]="1234567";
	map<string,string>::iterator curr,mend;
	for(curr=phone_book.begin(),mend=phone_book.end(); curr!=mend ;curr++){
		cout<<curr->first<<"="<<curr->second<<"\n";
	}
	
	set<int> ss;
	for(int i=0;i<10;i++){
		ss.insert(rand()%100);
	}
	
	map<string,string> mm;
	mm.insert(map<string,string>::value_type("hello","note me"));
	map<string,string>::iterator mit;
	mit=mm.find("hello");
	if(mit!=mm.end()){
		cout<<mit->first<<"="<<mit->second;
	}
	
}